﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="DataStore"
                   namespace="DataStore.Domain">
  <class name="CatalogItem" table="CatalogItem" >
    <id name="Id" column="CatalogItemId" type="Guid" >
      <generator class="guid" />
    </id>
    <property name="Type" />
    <property name="Comment" type="String" />
    <property name="Chapter" type="String" />
    <property name="Edition" type="String" />
    <property name="HowPublished" type="String" />
    <property name="DateWritten" type="DateTime" />
    <property name="DatePublished" type="DateTime" />
    <property name="Series" type="String" />
    <property name="Title" type="String" not-null="true"  />
    <property name="ReportType" type="String" />
    <property name="Volume" type="String" />
    <property name="Width"  />
    <property name="Height" />
    <property name="PurchaseDate" type="DateTime" />
    <property name="PurchasePrice" type="Single" />
    <property name="CurrentPrice" type="Single" />
    <property name="Rating" type="Int32" />
    <property name="Dedication" type="String" />
    <property name="ReadingDate" type="DateTime" />
    <property name="BorrowDate" type="DateTime" />
    <property name="LoCClassification" type="String" />
    <property name="DeweyClassification" type="String" />
    <property name="Copyright" type="String" />
    <property name="Quantity" type="Int32" />
    <property name="Location" type="String" />

    <many-to-one name="OtherClassification" class="Classification" column="ClassificationId" lazy="proxy" cascade="save-update" />
    <many-to-one name="Format" class="PublishingFormat" column="PublishingFormatId" lazy="proxy" cascade="save-update" />


    <set name="Categories" table ="catalogitem_category" lazy="true" cascade="save-update">
      <key>
        <column name="CatalogItemId" />
      </key>
      <many-to-many column="CategoryId" class="Category" />
    </set>
    <set name="Keywords" table ="catalogitem_keyword" lazy="true" cascade="save-update">
      <key>
        <column name="CatalogItemId" />
      </key>
      <many-to-many column="KeywordId" class="Keyword" />
    </set>


    <set name="Authors" table ="author_book" lazy="true" cascade="save-update">
      <key>
        <column name="BookId" />
      </key>
      <many-to-many column="PersonId" class="Author" />
    </set>
    
    <set name="Editors" table ="editor_book" lazy="true" cascade="save-update">
      <key>
        <column name="BookId" />
      </key>
      <many-to-many column="PersonId" class="Editor" />
    </set>
    <set name="Sponsors" table ="sponsor_book" lazy="true" cascade="save-update">
      <key>
        <column name="BookId" />
      </key>
      <many-to-many column="ComapnyId" class="Company" />
    </set>
    <set name="Links" lazy="true" table="CatalogItem_Links" cascade="all">
      <key column="Id" />
      <one-to-many class="Link" />
    </set>
    <set name="Cover" lazy="true" table="CatalogItem_Covers" cascade="all">
      <key column="Id" />
      <one-to-many class="Cover" />
    </set>

    <joined-subclass name="Book" table="Book">
      <key column="BookId" />
      <property name="ISBN" type="String" />
    </joined-subclass>

    <joined-subclass name="Journal" table="Journal">
      <key column="JournalId" />
      <property name="JournalName" type="String" />
      <property name="IssueNumber" type="String" />
      <property name="ISSN" type="String" />
      <set name="CompanyData" table="Journal_Company" cascade="save-update">
        <key column="JournalId" />
        <many-to-many column="CompanyId" class="Company" />
      </set>
      <set name="Stuff" table="Journal_Person" cascade="save-update">
        <key column="JournalId" />
        <many-to-many column="PersonId" class="Person" />
      </set>
    </joined-subclass>

    <joined-subclass name="Thesis" table="Thesis">
      <key column="ThesisId" />
      <property name="School" type="String" />
    </joined-subclass>
  </class>
</hibernate-mapping>
